<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket Demo</title>
</head>
<body>
    <p id="tip"></p>
    <input type="text" id="message" autocomplete="off"/>
    <button onclick="sendMessage()">发送消息</button>
    <script>
        let webSocket = new WebSocket("ws://127.0.0.1:8080/webSocket");
        webSocket.onopen = function () {
            document.getElementById("tip").innerText = "WebSocket连接成功";
        };
        webSocket.onclose = function () {
            document.getElementById("tip").innerText = "WebSocket连接关闭";
        };
        webSocket.onerror = function () {
            document.getElementById("tip").innerText = "WebSocket发生错误";
        };
        webSocket.onmessage = function (e) {
            console.log("WebSocket接收到消息：" + e.data);
        };

        function sendMessage() {
            let message = document.getElementById("message").value;
            webSocket.send(message);
        }
    </script>
</body>
</html>
